// JavaScript Document
oReview = 
{
	name:"oReview",
	url:"/review/dwr.php",
	authcodeUrl:"/authcode.gif",
	div:"LwordMsg",
	divType:0,
	faceType:"a",
	target:"IGact",
	pct:1,
	open:1,
	list:1,
	rand:0,
	page:0,
	act:"pct",	
	id:'',
	idExt:'',
	urs:'',
	rows:5,
	pageShowMaxNums:10,
	cookie:"srevew",
	divPrefix:"Review1_",
	
	cacheTxt:'',
	openId:0,
	cookieKey:'',
	json:new Json(),
	init:function(o)
	{
		var a = '<div id="'+this.divPrefix+'ShowForm"></div>',b = '<div id="'+this.divPrefix+'ShowList"></div>';
		o && this.set(o);
		_.e(this.div).innerHTML = this.divType?a+b:b+a;
		this.cookieKey = this.cookie+this.pct+this.id+this.idExt;
		this.open && this.openFrom();
		this.list && this.pg();
	},
	openFrom:function()
	{
		this.closeReview();
		_.e(this.divPrefix+'ShowForm').innerHTML = this.login()
			?['<form onsubmit="return '+this.name+'.submitFrom(this);" action="'+this.url+'" method="post" target="'+this.target+'">',
    			'<table cellspacing="0" cellpadding="0" width="680" align="center" border="0">',
      			'<tbody><tr><td>咨询或评论： （字数在2~120之间）</td>',
          		'<td align="right">&nbsp;</td>',
        		'</tr><tr>',
          		'<td align="middle" colspan="2">',
                '<textarea id="contents" name="contents" rows="7" cols="120">'+(this.cacheTxt||'')+'</textarea>',
                '</td></tr><tr>',
          		'<td align="left" height="70">',
          			'请输入右侧验证码：<span id="leaveMsg_authcode"><img src="'+this.authcodeUrl+'" /></span>',
              		' <input class="ime" maxlength="4" name="verifycode" />',
              	'</td>',
          		'<td align="right"><input type="submit" name="postSubmit" value=" 确　定 "/></td>',
        		'</tr></tbody>',
    			'</table>',
    			'</form>'].join(''):'<div id="LeaveMsg"> 您要先<a href="/login.php">登录</a>才能给店主留言:) </div>';
		//alert("s");
	},
	submitFrom:function(o)
	{
		if(o.contents) this.cacheTxt = 	o.contents.value;
		if(o.contents && (o.contents.value.length < 2 || o.contents.value.length > 240))
		{
			if(o.contents.value.length < 2)
			{
				this.alert("提示:请输入留言内容,并不可以少于10个字符!");
			}else
			{
				this.alert("提示:您输入的留言内容,不可以大于120个汉字或240个字符!");
			}
			o.contents.focus();
		}else if(o.verifycode && o.verifycode.value.length != 4)
		{
			this.alert("提示:认真请输入验证码,并确认是否有误!");
			o.verifycode.focus();
		}else
		{
			o.postSubmit.value			 =	'提交中..';
			o.postSubmit.disabled		 =	true;
			this.json.load(url.en({
									Pact:"insert",
									pct:this.pct,
									data_id:this.id+this.idExt,
									data_urs:this.urs,
									contents:o.contents.value,
									verifycode:o.verifycode.value
								},this.url),this.name+".insertComeBack");
		}
		return false;
	},
	insertComeBack:function(o)
	{
		if(o[0])
		{
			$.cookie(this.cookieKey+'rand',(this.rand = _.rand()));
			this.cacheTxt = "";
			this.pg(1);
		}
		this.openFrom();
		this.alert(o[1]);
	},
	openReview:function(id)
	{
		id = id || this.openId;
		this.openId = id;
		var el   = this.divPrefix+'ShowTD_'+id;
		var o    = _.e(el);
		!o.oldHTML && (o.oldHTML=o.innerHTML);
		o.innerHTML = ['<form onsubmit="return '+this.name+'.sumbitReview(this)" method="post">',
					   '<textarea name="contents" cols="45" rows="3">'+(this.cacheTxt||'')+'</textarea>',
					   '<br /><input type="submit" name="postSubmit" value=" 提 交 " />',
					   ' [<a href="javascript:'+this.name+'.closeReview();" style="color:#FF6600;">返回</a>]</form>'].join('');
	},
	closeReview:function()
	{
		if(this.openId)
		{
			var el      = this.divPrefix+'ShowTD_'+this.openId;
			var o       = _.e(el);
			o.innerHTML = o.oldHTML;
			this.openId = 0;
			this.open && this.openFrom();
		}		
	},
	sumbitReview:function(o)
	{
		if(o.contents) this.cacheTxt = 	o.contents.value;
		if(o.contents && (o.contents.value.length < 2 || o.contents.value.length > 240))
		{
			if(o.contents.value.length < 2)
			{
				this.alert("提示:请输入留言内容,并不可以少于10个字符!");
			}else
			{
				this.alert("提示:您输入的留言内容,不可以大于120个汉字或240个字符!");
			}
			o.contents.focus();
		}else
		{
			o.postSubmit.value			 =	'提交中..';
			o.postSubmit.disabled		 =	true;
			this.json.load(url.en({
									Pact:"review",
									pct:this.pct,
									data_id:this.id+this.idExt,
									id:this.openId,
									data_urs:this.urs,
									contents:o.contents.value
								},this.url),this.name+".reviewComeBack");
		}
		return false;
	},
	reviewComeBack:function(o)
	{
		if(!o[0])
		{
			this.openReview();
		}else
		{
			$.cookie(this.cookieKey+'rand',(this.rand = _.rand()));
			this.cacheTxt = "";
			this.pg();
		}
		this.alert(o[1]);
	},
	del:function(id)
	{
		if(id && window.confirm("提示:删除将完法恢复,你确认要删除吗?"))
		{
			this.json.load(url.en({
									Pact:"del",
									id:id
								},this.url),this.name+".delComeBack");
		}
	},
	delComeBack:function(o)
	{
		if(o[0])
		{
			$.cookie(this.cookieKey+'rand',(this.rand = _.rand()));
			this.pg();
		}
		this.alert(o[1]);
	},
	pg:function(page)
	{
		page = page || this.page || $.cookie(this.cookieKey+'pg') || 1;
		var rand = this.rand || $.cookie(this.cookieKey+'rand');
		$.cookie(this.cookieKey+'pg',(this.page = page));
		this.json.load(url.en({
								Pact:this.act,
								pct:this.pct,
								data_id:this.id+this.idExt,
								data_urs:this.urs,
								page:page,
								rows:this.rows,
								rand:rand
							},this.url),this.name+".pgInit");
	},
	pgInit:function(o)
	{
		var i,rs = [],d,nextPage = this.subPg(o.all,o.ths,o.pgc).join(' <wbr />');
		for (i=0; i <o.data.length; i++)
    	{
    		d = o.data[i];
    		rs.push('<table id="list" align="center" '+(i%2?' bgcolor="#f8f8f8" ':'')+' border="0" cellpadding="3" cellspacing="0" width="100%">');
        	rs.push('<tr colspan="2" align="left">');
        	rs.push('<td> <a href="#">'+(d.data_urs == d.urs?'<span style="color:#FF0000;font-weight:bold">店主自己</span>|':'')+d['urs']+'</a> </td>');
        	rs.push('</tr>');
        	rs.push('<tr>');
        	rs.push('<td><img src="'+__scfg__.staticUrl+'imgs/comm_btn_question.gif" align="absmiddle"> ');
        	rs.push(this.de(d.contents));
        	rs.push(' </td>');
        	rs.push('<td width="150" valign="bottom"><font color="#959595"> ['+_.time(d.save_time)+'] </font></td>');
        	rs.push('</tr>');
        	if(d.review)
        	{
	        	rs.push('<tr>');
	        	rs.push('<td style="color:#FF6600;"><img src="'+__scfg__.staticUrl+'imgs/comm_btn_answer.gif" align="absmiddle"> '+this.de(d.review)+'  </td>');
	        	rs.push('<td width="150" valign="bottom"><font color="#959595"> ['+_.time(d.review_time)+'] </font></td>');
	        	rs.push('</tr>');
        	}else if(d.data_urs == this.getUrs() || d.urs == this.getUrs())
        	{
        		rs.push('<tr>');
	        	rs.push('<td colspan="2" id="'+this.divPrefix+'ShowTD_'+d.id+'"><font color="#959595">等待卖家回复中... [<a href="javascript:'+this.name+'.openReview('+d.id+');" style="color:#FF6600;">回复</a>] [<a href="javascript:'+this.name+'.del('+d.id+');" style="color:#FF6600;">删除</a>]</font></td>');
	        	rs.push('</tr>');
        	}
        	rs.push('</table>');
        }
        rs.push('<div id="LeaveMsgPage" align="right"> <span id="html_tem_msgPage">'+nextPage+'</span> </div>')
		_.e(this.divPrefix+'ShowList').innerHTML = rs.join('');
	},
	subPg:function(all,ths,pgc,max)
	{
	   var rs=[],t={},i;	   	   
	   all      = all || 1;
	   ths      = ths || 1;
	   pgc      = pgc || 1;
	   t['t']	= max || this.pageShowMaxNums;
	   t['m']	= Math.ceil(t['t']/2);
	   if(pgc > t['t'])
		{
			t['C']		=t['t'];	
			t['Begin']	=true;
			t['End']	=true;
			if(ths <= t['m'])
			{
				t['Start']	= 1;
				t['Begin']	= false;
			}else if(pgc-ths < t['m'])
			{
				t['Start']	= pgc-t['t']+1;
				t['End']	= false;
			}else
			{
				t['Start']	= ths-t['m']+1;
			}
		}else
		{
			t['C']		=pgc;	//
			t['Begin']	=false;
			t['End']	=false;
			t['Start']	=1;
		}
		t['Next']		= ths!=pgc && pgc>1?true:false;
		t['Previous']	= ths!=1 && pgc>1?true:false;
		
		rs.push('总共有'+all+'条评论,共'+pgc+'页,第'+ths+'页 ');
		if(t['Begin'])		rs.push('<a href="javascript:gReF.pg(1)">开始</a>');
		if(t['Previous'])	rs.push('<a href="javascript:gReF.pg('+(ths-1)+')">上一页</a>');
		for(i=t['Start'];i<(t['Start']+t['C']);i++)
		{
			if(i==ths)
			{
			     rs.push(ths);
			}else
			{
			    rs.push('<a href="javascript:gReF.pg('+i+')">第'+i+'页</a>');
			}
		}
		if(t['Next'])	rs.push('<a href="javascript:gReF.pg('+(ths+1)+')">下一页</a>');
		if(t['End'])	rs.push('<a href="javascript:gReF.pg('+pgc+')">最后</a>');
		t ={};
	    return rs;
	},
	en:function(str)
    {
        return str.replace(/<[^<]*icon_([^<]*)\.gif[^<]*>/ig,'[`a_$1`]')
				  .replace(/<[^<]*face\/([^\/]*)\/([^\/]*)\.gif[^<]*>/ig,'[`$1_$2`]')
				  .replace(/<([^<]*)>/ig,"");
    },
    de:function(str)
    {
        return str.replace(/<[^<]*icon_([^<]*)\.gif[^<]*>/ig,'[`a_$1`]')
				.replace(/<[^<]*face\/([^\/]*)\/([^\/]*)\.gif[^<]*>/ig,'[`$1_$2`]')
				.replace(/<br \/>/ig,'\n')
				.replace(/</g,"&lt;")
				.replace(/>/g,">")
				.replace(/\[u\](.*?)\[\/u\]/igm,"<u>$1</u>")
				.replace(/\[i\](.*?)\[\/i\]/igm,"<i>$i</i>")
				.replace(/\[b\](.*?)\[\/b\]/igm,"<b>$1</b>")
				.replace(/\[p\](.*?)\[\/p\]/igm,"<p>$1</p>")
				.replace(/\[`([A-Za-z0-9])_(.*?)`\]/ig,"<img src=\"http://www.56.com/images/face/$1/$2.gif\" /><wbr />")
				.replace(/\n/g,"<br />");
    },
    alert:function(str)
    {
    	alert(str);
    },
    login:function()
    {
    	return urs.login();
    },
    getUrs:function()
    {
    	return urs.login()?urs.urs:'';
    },
    set:function(o)
	{
		for(var k in o) this[k] = o[k];
	}
};